const path = require('path')
const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')

const getPath = p => path.resolve(__dirname, p)

process.env.BABEL_ENV = 'development'

module.exports = function() {
  return {
    mode: 'development',
    entry: {
      index: getPath('src/index.js'),
    },
    devServer: {
      port: 3333,
      contentBase: getPath('public'),
      hot: true,
      inline: true,
    },
    output: {
      path: getPath('build'),
      filename: 'bundle.js',
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          use: [
            'thread-loader',
            {
              loader: 'babel-loader',
              options: {
                cacheDirectory: true,
              },
            },
          ],
        },
      ],
    },
    plugins: [
      new ProgressBarPlugin(),
      new HardSourceWebpackPlugin(),
      new HtmlWebpackPlugin({
        title: 'vdom',
        template: getPath('src/index.html'),
      }),
    ],
  }
}
